package com.youlian.cloud.gateway.controller;

import com.youlian.cloud.gateway.config.SwaggerConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger.web.*;

import java.util.List;

/**
 * swagger的UI资源请求类
 * @author liuhx
 * @create 2019/08/02 16:37
 * @email liuhx@elab-plus.com
 **/
@RestController
@RequestMapping("/swagger-resources")
public class SwaggerResourceController {
    @Autowired
    private SwaggerConfiguration swaggerResourceProvider;

//    @Autowired
//    public SwaggerResourceController(SwaggerConfiguration swaggerResourceProvider) {
//        this.swaggerResourceProvider = swaggerResourceProvider;
//    }

    @RequestMapping(value = "/configuration/security")
    public ResponseEntity<SecurityConfiguration> securityConfiguration() {
        return new ResponseEntity(SecurityConfigurationBuilder.builder().build(), HttpStatus.OK);
    }

    @RequestMapping(value = "/configuration/ui")
    public ResponseEntity<UiConfiguration> uiConfiguration() {
        return new ResponseEntity<>(UiConfigurationBuilder.builder().build(), HttpStatus.OK);
    }

    @RequestMapping
    public ResponseEntity<List<SwaggerResource>> swaggerResources() {
        return new ResponseEntity(swaggerResourceProvider.get(), HttpStatus.OK);
    }
}
